package com.swak.algs.node;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

@Getter
@Setter
@Accessors(chain = true)
@ToString(exclude = { "left", "right" })
public class TreeNode {

	public int val;
	public TreeNode left;
	public TreeNode right;

	/**
	 * 平衡树
	 */
	public static TreeNode newBlanceTree() {
		TreeNode head = new TreeNode();
		head.val = 1;

		TreeNode node = head;
		node.left = new TreeNode().setVal(2);
		node.right = new TreeNode().setVal(3);

		node = head.left;
		node.left = new TreeNode().setVal(4);
		node.right = new TreeNode().setVal(5);

		node = head.right;
		node.left = new TreeNode().setVal(6);
		node.right = new TreeNode().setVal(7);
		return head;
	}
	
	/**
	 * 搜索树
	 */
	public static TreeNode newSearchTree() {
		TreeNode head = new TreeNode();
		head.val = 4;

		TreeNode node = head;
		node.left = new TreeNode().setVal(2);
		node.right = new TreeNode().setVal(6);

		node = head.left;
		node.left = new TreeNode().setVal(1);
		node.right = new TreeNode().setVal(3);

		node = head.right;
		node.left = new TreeNode().setVal(5);
		node.right = new TreeNode().setVal(7);
		return head;
	}

	/**
	 * 非镜面树
	 * 
	 * @return
	 */
	public static TreeNode newNoMirrorTree() {
		TreeNode head = new TreeNode();
		head.val = 1;

		TreeNode node = head;
		node.left = new TreeNode().setVal(2);
		node.right = new TreeNode().setVal(3);

		node = head.left;
		node.left = new TreeNode().setVal(4);
		node.left.left = new TreeNode().setVal(10);
		node.right = new TreeNode().setVal(5);
		node.right.right = new TreeNode().setVal(9);

		node = head.right;
		node.left = new TreeNode().setVal(6);
		node.right = new TreeNode().setVal(7);
		node.right.right = new TreeNode().setVal(8);
		return head;
	}
}
